package com.bysc.joinservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bysc.commonutils.vo.JoinForm;
import com.bysc.joinservice.entity.vo.JoinFormQueryVo;
import com.bysc.joinservice.mapper.JoinFormMapper;
import com.bysc.joinservice.service.JoinFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kkk
 * @since 2024-05-28
 */
@Service
public class JoinFormServiceImpl extends ServiceImpl<JoinFormMapper, JoinForm> implements JoinFormService {
    @Autowired
    JoinFormMapper joinFormMapper;

    @Override
    public IPage<JoinForm> getJoinFormByPage(Page<JoinForm> page1, JoinFormQueryVo queryVo) {
        String name = queryVo.getName();
        String majorId = queryVo.getMajorId();
        String collegeId = queryVo.getCollegeId();
        Integer gender = queryVo.getGender();
        Integer status = queryVo.getStatus();
        String deptId = queryVo.getDeptId();
        String start = queryVo.getStart();
        String end = queryVo.getEnd();
        LambdaQueryWrapper<JoinForm> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(majorId)) {
            wrapper.eq(JoinForm::getMajorId, majorId);
        }
        if (!StringUtils.isEmpty(collegeId)) {
            wrapper.eq(JoinForm::getCollegeId, collegeId);
        }
        if (!StringUtils.isEmpty(gender)) {
            wrapper.like(JoinForm::getGender, gender);
        }
        if (status != null) {
            wrapper.eq(JoinForm::getStatus, status);
        }
        if (!StringUtils.isEmpty(deptId)) {
            wrapper.like(JoinForm::getDeptId, deptId);
        }
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(JoinForm::getName, name);
        }

        if (!StringUtils.isEmpty(start)) {
            wrapper.ge(JoinForm::getGmtCreate, start);
        }
        if (!StringUtils.isEmpty(end)) {
            wrapper.le(JoinForm::getGmtCreate, end);
        }
        IPage<JoinForm> page = joinFormMapper.selectPage(page1, wrapper);
        return page;
    }

}
